package dg;

public class demo2 {
    public static void main(String[] args) {
        //递归求5的阶乘
        int factorial = getFactorial(5);
        System.out.println(factorial);

    }

    public static int getFactorial(int n) {
        //5!=5*4*3*2*1
        //5!=5*4!
        //4!=4*3!
        //3!=3*2!
        //2!=2*1!
        //1!=1
        if (n == 1) {
            return 1;
        } else {
            return n * getFactorial(n - 1);
        }
    }
}
